Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /** |
||
18 | function dark(state, format, visibility, upgrade, data, util) { |
||
19 | let ct = this; |
||
20 | ct.state = state; |
||
21 | ct.data = data; |
||
22 | ct.util = util; |
||
23 | ct.format = format; |
||
24 | |||
25 | ct.darkProduction = function() { |
||
26 | let production = 0; |
||
27 | for (let element in data.elements) { |
||
28 | let exotic = data.elements[element].exotic; |
||
29 | if (!state.player.resources[exotic].unlocked) { |
||
30 | continue; |
||
31 | } |
||
32 | production += Math.floor(Math.max(0, Math.log(state.player.resources[exotic].number))); |
||
33 | } |
||
34 | |||
35 | return production; |
||
36 | }; |
||
37 | |||
38 | ct.darkPrestige = function() { |
||
39 | let resources = state.player.resources; |
||
40 | let production = ct.darkProduction(); |
||
41 | |||
42 | resources.dark_matter.number += production; |
||
43 | resources.dark_matter.unlocked = true; |
||
44 | |||
45 | for(let key in data.elements){ |
||
46 | let element = data.elements[key]; |
||
47 | state.player.resources[element.exotic].number = 0; |
||
48 | for(let up in data.exotic_upgrades){ |
||
49 | state.player.exotic_upgrades[key][up] = false; |
||
50 | } |
||
51 | } |
||
52 | for(let slot of state.player.element_slots){ |
||
53 | if(!slot){ |
||
54 | continue; |
||
55 | } |
||
56 | upgrade.resetElement(state.player, slot.element); |
||
57 | } |
||
58 | |||
59 | for(let i in state.player.element_slots){ |
||
60 | state.player.element_slots[i] = null; |
||
61 | } |
||
62 | }; |
||
63 | |||
64 | ct.buyDarkUpgrade = function(name) { |
||
65 | let upgrades = state.player.dark_upgrades; |
||
66 | let price = data.dark_upgrades[name].price; |
||
67 | let currency = 'dark_matter'; |
||
68 | upgrade.buyUpgrade(state.player, |
||
69 | upgrades, |
||
70 | data.dark_upgrades[name], |
||
71 | name, |
||
72 | price, |
||
73 | currency); |
||
74 | }; |
||
75 | |||
76 | ct.visibleDarkUpgrades = function() { |
||
77 | return visibility.visible(data.dark_upgrades, isDarkUpgradeVisible, 0); |
||
78 | }; |
||
79 | |||
80 | // here we receive not the name of the element, but the index in the element_slots |
||
81 | function isDarkUpgradeVisible(name, index) { |
||
82 | return visibility.isUpgradeVisible(name, index, data.dark_upgrades[name]); |
||
83 | } |
||
84 | } |
||
85 |